<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>动态获取菜单</title>
    <link rel="stylesheet" href="/layui/css/layui.css"  media="all">
</head>
<body>
<input type="button" value="get" style="width:150px;" class="button_blue" onclick="getAjax()"/>
<script>
    //菜单循环遍历打印拼接操作

    function   getAjax () {
        $.ajax( {
            url :'/back',
            type : 'post',
            dataType : 'json',
            success : function(data) {
                console(date);
                var menu = "";           //定义变量存储
                for(var i = 0;i<data.length;i++){
                    menu += "<li class='layui-nav-item '>"
                    if(data[i]. == 0){           //取出父元素的菜单，拼进页面
                        menu +=        "<a href='javascript:;'>"+data[i].menuName+"</a>"
                        for(var j = 0;j<data.length;j++){ //继续遍历这几条数据
                            if(data[j].mid > data[i].mid && data[j].mid < (data[i].mid)+1000){       //取出这个父元素所对应的子元素
                                menu +=    "<dl class='layui-nav-child'>"
                                menu +=        "<dd>"
                                menu +=            "<a href='"+data[j].menuPath+"' target='option'>"+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+data[j].menuName+"</a>"
                                menu +=        "</dd>"
                                menu +=    "</dl>"
                            }
                        }
                    }
                    menu +=    "</li>";
                }
                $("#nav").html(menu);
                var element = layui.element;
                element.init()//初始化element事件，使菜单展开
            }
        });
    })

</script>
<script src="/layui/layui.js" charset="utf-8"></script>
</body>
</html>